/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.max.cjs.dao.jdbc;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.max.cjs.dao.interfac.ISystemUserDao;
import org.max.cjs.dao.util.MySQLConnect;
import org.max.cjs.model.ext.SystemUser;

/**
 *
 * @author user
 */
public class SystemUserDao implements ISystemUserDao{
    
    @Override
    public List<SystemUser> getByCredential(String user, String password) throws Exception{
        MySQLConnect conn = new MySQLConnect("socioscjava");
        conn.openConnection();
        List<SystemUser> list = new ArrayList<SystemUser>();
        String sql = "select user_name, password from system_user "
                + "where user_name='(us)' and password='(pas)'"
                .replace("(us)", user)
                .replace("(pas)", password);
        ResultSet rs = conn.getConnection().createStatement().executeQuery(sql);
        SystemUser sysUs;
        while (rs.next()) {
            sysUs = new SystemUser();
            sysUs.setUser("" + rs.getString(1));
            sysUs.setPassword("" + rs.getString(2));
            list.add(sysUs);
        }
        conn.closeConnection();
        return list;
    }
            
}
